﻿using UnityEngine;
using System;
using System.Collections.Generic;
using LuaInterface;
using UnityEditor;
using UnityEngine.UI;

using BindType = ToLuaMenu.BindType;
using System.Reflection;

public static class CustomSettings
{
    public static string saveDir = Application.dataPath + "/LuaFramework/Source/Generate/";    
	public static string toluaBaseType = Application.dataPath + "/LuaFramework/ToLua/BaseType/";
	public static string baseLuaDir = Application.dataPath + "/LuaFramework/Tolua/Lua/";
	public static string injectionFilesPath = Application.dataPath + "/LuaFramework/ToLua/Injection/";

    //导出时强制做为静态类的类型(注意customTypeList 还要添加这个类型才能导出)
    //unity 有些类作为sealed class, 其实完全等价于静态类
    public static List<Type> staticClassTypes = new List<Type>
    {        
        typeof(UnityEngine.Application),
        typeof(UnityEngine.Time),
        typeof(UnityEngine.Screen),
        typeof(UnityEngine.SleepTimeout),
        typeof(UnityEngine.Input),
        typeof(UnityEngine.Resources),
		typeof(UnityEngine.Physics),
		typeof(UnityEngine.Physics2D),
        typeof(UnityEngine.RenderSettings),
        typeof(UnityEngine.QualitySettings),
        typeof(UnityEngine.GL),
		typeof(UnityEngine.Graphics),
		typeof(UnityEngine.ContactPoint)
    };

    //附加导出委托类型(在导出委托时, customTypeList 中牵扯的委托类型都会导出， 无需写在这里)
    public static DelegateType[] customDelegateList = 
    {        
        _DT(typeof(Action)),                
        _DT(typeof(UnityEngine.Events.UnityAction)),
        _DT(typeof(System.Predicate<int>)),
        _DT(typeof(System.Action<int>)),
        _DT(typeof(System.Comparison<int>)),
        _DT(typeof(System.Func<int, int>)),
        _DT(typeof(DG.Tweening.TweenCallback)),
        _DT(typeof(UnityEngine.Events.UnityAction<UnityEngine.Vector2>)),
        _DT(typeof(System.Action<SpriteLayerInputManager.TouchEvent>)),
    };

    //在这里添加你要导出注册到lua的类型列表
    public static BindType[] customTypeList =
    {                  
        _GT(typeof(LuaInjectionStation)),
        _GT(typeof(InjectType)),
        _GT(typeof(Debugger)).SetNameSpace(null),    

		_GT(typeof(DG.Tweening.AutoPlay)),
		_GT(typeof(DG.Tweening.AxisConstraint)),
		_GT(typeof(DG.Tweening.Ease)),
		_GT(typeof(DG.Tweening.ScrambleMode)),
		_GT(typeof(DG.Tweening.TweenType)),
		_GT(typeof(DG.Tweening.UpdateType)),
        _GT(typeof(DG.Tweening.DOTween)),
        _GT(typeof(DG.Tweening.Tween)).SetBaseType(typeof(System.Object)).AddExtendType(typeof(DG.Tweening.TweenExtensions)),
        _GT(typeof(DG.Tweening.Sequence)).AddExtendType(typeof(DG.Tweening.TweenSettingsExtensions)),
        _GT(typeof(DG.Tweening.Tweener)).AddExtendType(typeof(DG.Tweening.TweenSettingsExtensions)),
        _GT(typeof(DG.Tweening.LoopType)),
        _GT(typeof(DG.Tweening.PathMode)),
        _GT(typeof(DG.Tweening.PathType)),
		_GT(typeof(DG.Tweening.RotateMode)),

        _GT(typeof(DG.Tweening.DOTweenAnimation)),
        _GT(typeof(DG.Tweening.DOTweenPath)),
        _GT(typeof(DG.Tweening.DOTweenVisualManager)),
        _GT(typeof(DG.Tweening.Core.ABSSequentiable)),
        _GT(typeof(DG.Tweening.TweenParams)),
        _GT(typeof(DG.Tweening.DOVirtual)),
        _GT(typeof(DG.Tweening.EaseFactory)),
        _GT(typeof(DG.Tweening.Core.TweenerCore<Vector3, Vector3, DG.Tweening.Plugins.Options.VectorOptions>)).SetWrapName("TweenerCoreV3V3VO").SetLibName("TweenerCoreV3V3VO"),
        _GT(typeof(DG.Tweening.Core.TweenerCore<Vector2, Vector2, DG.Tweening.Plugins.Options.VectorOptions>)).SetWrapName("TweenerCoreV2V2VO").SetLibName("TweenerCoreV2V2VO"),
        _GT(typeof(DG.Tweening.Core.TweenerCore<Color, Color, DG.Tweening.Plugins.Options.ColorOptions>)),




        _GT(typeof(Component)).AddExtendType(typeof(DG.Tweening.ShortcutExtensions)),
        _GT(typeof(Transform)).AddExtendType(typeof(DG.Tweening.ShortcutExtensions)).AddExtendType(typeof(TransformExtension)),
//        _GT(typeof(Light)).AddExtendType(typeof(DG.Tweening.ShortcutExtensions)),
        _GT(typeof(Material)).AddExtendType(typeof(DG.Tweening.ShortcutExtensions)),
		_GT(typeof(Rigidbody)).AddExtendType(typeof(DG.Tweening.ShortcutExtensions)),
        _GT(typeof(Rigidbody2D)).AddExtendType(typeof(DG.Tweening.ShortcutExtensions)).AddExtendType(typeof(DG.Tweening.ShortcutExtensions43)),
        _GT(typeof(Camera)).AddExtendType(typeof(DG.Tweening.ShortcutExtensions)),
        _GT(typeof(AudioSource)).AddExtendType(typeof(DG.Tweening.ShortcutExtensions)),
//        _GT(typeof(LineRenderer)).AddExtendType(typeof(DG.Tweening.ShortcutExtensions)),
//		_GT(typeof(TrailRenderer)).AddExtendType(typeof(DG.Tweening.ShortcutExtensions)),    
        _GT(typeof(SpriteRenderer)).AddExtendType(typeof(DG.Tweening.ShortcutExtensions)).AddExtendType(typeof(DG.Tweening.ShortcutExtensions43)),


         //UGUI
        _GT(typeof(RectTransform)).AddExtendType(typeof(DG.Tweening.ShortcutExtensions46)).AddExtendType(typeof(DG.Tweening.ShortcutExtensions)).AddExtendType(typeof(TransformExtension)),
        _GT(typeof(Text)).AddExtendType(typeof(DG.Tweening.ShortcutExtensions46)).AddExtendType(typeof(DG.Tweening.ShortcutExtensions)),
        _GT(typeof(Image)).AddExtendType(typeof(DG.Tweening.ShortcutExtensions46)).AddExtendType(typeof(DG.Tweening.ShortcutExtensions)),
        _GT(typeof(RawImage)).AddExtendType(typeof(DG.Tweening.ShortcutExtensions46)).AddExtendType(typeof(DG.Tweening.ShortcutExtensions)),
        _GT(typeof(ScrollRect)).AddExtendType(typeof(DG.Tweening.ShortcutExtensions46)).AddExtendType(typeof(DG.Tweening.ShortcutExtensions)),
        _GT(typeof(Button)).AddExtendType(typeof(DG.Tweening.ShortcutExtensions46)).AddExtendType(typeof(DG.Tweening.ShortcutExtensions)),
        _GT(typeof(Toggle)).AddExtendType(typeof(DG.Tweening.ShortcutExtensions46)).AddExtendType(typeof(DG.Tweening.ShortcutExtensions)),
        _GT(typeof(CanvasGroup)).AddExtendType(typeof(DG.Tweening.ShortcutExtensions46)).AddExtendType(typeof(DG.Tweening.ShortcutExtensions)),
        _GT(typeof(Slider)).AddExtendType(typeof(DG.Tweening.ShortcutExtensions46)).AddExtendType(typeof(DG.Tweening.ShortcutExtensions)),
        _GT(typeof(Graphics)).AddExtendType(typeof(DG.Tweening.ShortcutExtensions46)).AddExtendType(typeof(DG.Tweening.ShortcutExtensions)),


        _GT(typeof(UnityEngine.Events.UnityEvent)),
		_GT(typeof(UnityEngine.SceneManagement.SceneManager)),
		_GT(typeof(UnityEngine.SceneManagement.LoadSceneMode)),
		_GT(typeof(UnityEngine.SceneManagement.Scene)),
        _GT(typeof(Behaviour)),
        _GT(typeof(MonoBehaviour)),        
        _GT(typeof(GameObject)),
        _GT(typeof(TrackedReference)),
		_GT(typeof(Application)),
		_GT(typeof(RuntimePlatform)),
		_GT(typeof(Physics)),
		_GT(typeof(Physics2D)),
		_GT(typeof(Collider)),
		_GT(typeof(Collider2D)),
        _GT(typeof(Time)),        
        _GT(typeof(Texture)),
        _GT(typeof(Texture2D)),
        _GT(typeof(Shader)),        
        _GT(typeof(Renderer)),
        _GT(typeof(WWW)),
        _GT(typeof(Screen)),        
        _GT(typeof(CameraClearFlags)),
        _GT(typeof(AudioClip)),        
        _GT(typeof(AssetBundle)),
        _GT(typeof(ParticleSystem)),
        _GT(typeof(AsyncOperation)).SetBaseType(typeof(System.Object)),        
//        _GT(typeof(LightType)),
		_GT(typeof(SleepTimeout)),

        _GT(typeof(Animator)),
        _GT(typeof(Input)),
        _GT(typeof(KeyCode)),
        _GT(typeof(SkinnedMeshRenderer)),
        _GT(typeof(Space)),      
       

        _GT(typeof(MeshRenderer)),

        _GT(typeof(BoxCollider)),
        _GT(typeof(MeshCollider)),
        _GT(typeof(SphereCollider)),        
        _GT(typeof(CharacterController)),
        _GT(typeof(CapsuleCollider)),
		_GT(typeof(ContactPoint)),
		_GT(typeof(Collision)),


		_GT(typeof(BoxCollider2D)),
		_GT(typeof(PolygonCollider2D)),
		_GT(typeof(CircleCollider2D)),        
		_GT(typeof(EdgeCollider2D)),
		_GT(typeof(CapsuleCollider2D)),
		_GT(typeof(Collision2D)),
		_GT(typeof(Joint2D)),
        
        _GT(typeof(Animation)),        
        _GT(typeof(AnimationClip)).SetBaseType(typeof(UnityEngine.Object)),        
        _GT(typeof(AnimationState)),
        _GT(typeof(AnimationBlendMode)),
        _GT(typeof(QueueMode)),  
        _GT(typeof(PlayMode)),
        _GT(typeof(WrapMode)),

        _GT(typeof(QualitySettings)),
        _GT(typeof(RenderSettings)),                                                   
		_GT(typeof(BlendWeights)),           
        _GT(typeof(RenderTexture)),
		_GT(typeof(RenderTextureFormat)),
        _GT(typeof(Resources)),     
        _GT(typeof(LuaProfiler)),

		_GT(typeof(Spine.Unity.SkeletonRenderer)),
		_GT(typeof(Spine.Unity.SpineAnimation)),
		_GT(typeof(Spine.Unity.SkeletonGraphic)),
		_GT(typeof(Spine.Unity.SkeletonAnimator)),
		_GT(typeof(Spine.Unity.SpineAttachment)),
		_GT(typeof(Spine.Unity.SpineBone)),
		_GT(typeof(Spine.Unity.SpineSlot)),
//		_GT(typeof(Spine.Unity.SpineSkin)),
		_GT(typeof(Spine.Unity.SpineEvent)),
		_GT(typeof(Spine.Unity.SpineAtlasRegion)),

		//sprite
		_GT(typeof(Sprite)),
		_GT(typeof(SpriteAlignment)),

		//framework
		_GT(typeof(PluginManager)),
		_GT(typeof(ModuleManager)),


		//bone2D
		_GT(typeof(Bones2D.AnimEvent)),
        _GT(typeof(Bones2D.Armature)).AddExcludeSetter("isUGUI"),
		_GT(typeof(Bones2D.ArmatureMesh)),
		_GT(typeof(Bones2D.Bone)),
		_GT(typeof(Bones2D.PoseData)),
		_GT(typeof(Bones2D.Slot)),
		_GT(typeof(Bones2D.SpriteFrame)),
            _GT(typeof(Bones2D.SpriteMesh)).AddExcludeField("isEdit").AddExcludeField("weightVertices"),
		_GT(typeof(Bones2D.TextureFrame)),
        _GT(typeof(Bones2D.TextureFrames)).AddExcludeFunc("UpdateFrames").AddExcludeFunc("ParseSpineAtlasText").AddExcludeFunc("ParseDragonBoneAtlasText"),
		_GT(typeof(Bones2D.UIFrame)),
        _GT(typeof(Bones2D.UIMesh)).AddExcludeField("weightVertices").AddExcludeField("isEdit"),

		_GT(typeof(Messenger)),
		_GT(typeof(MessengerBehaviour)),

		//paint
        _GT(typeof(RenderTexturePainter)).AddExcludeField("gizmosColor"),
		_GT(typeof(RenderTexturePainter.PaintType)),
        _GT(typeof(PaintCompleteChecker)).AddExcludeField("gridDefaultStatus").AddExcludeField("sourceTexture")
                .AddExcludeField("penTexture").AddExcludeField("enableColor").AddExcludeField("gridScale").AddExcludeField("editorBrushSize")
                .AddExcludeField("disableColor").AddExcludeField("gridsDic").AddExcludeField("enablesDic"),
		_GT(typeof(ScribbleCheckData)),
		_GT(typeof(Paint3D)),
        _GT(typeof(Painter)).AddExcludeField("gizmosColor"),
		_GT(typeof(Painter.PaintType)),
		_GT(typeof(PainterCheckData)),
        _GT(typeof(PainterProgressChecker)).AddExcludeField("gridDefaultStatus").AddExcludeField("sourceTexture")
                .AddExcludeField("penTexture").AddExcludeField("enableColor").AddExcludeField("gridScale").AddExcludeField("editorBrushSize")
                .AddExcludeField("disableColor").AddExcludeField("gridsDic").AddExcludeField("enablesDic"),
		_GT(typeof(ResizePainterQuad)),

		//particle2d
        _GT(typeof(Particle2D)),
        _GT(typeof(Particle2DSystem)).AddExcludeFunc("ReadConfig"),
        _GT(typeof(Particle2DUGUI)).AddExcludeFunc("ReadConfig"),

		//sprite layout
		_GT(typeof(Native2dAnchor)),
		_GT(typeof(Native2dCamera2DSetting)),
		_GT(typeof(Native2DLayerScaler)),
		_GT(typeof(Native2dScreenUtil)),


		_GT(typeof(SpriteDrag)),
		_GT(typeof(SpriteMask)),
		_GT(typeof(SpriteMask2)),
		_GT(typeof(SpriteTouch)),
        _GT(typeof(SpriteLayerInputManager)),
        _GT(typeof(SpriteLayerInputManager.TouchEvent)),

		//ugui exstension
		_GT(typeof(Canvas)),
		_GT(typeof(PageView)),
		_GT(typeof(PageIndicator)),
		_GT(typeof(CenterView)),
		_GT(typeof(CenterViewItem)),
		_GT(typeof(LoopScrollView)),
		_GT(typeof(UIPolygon)),
		_GT(typeof(EventTriggerListener)),
		_GT(typeof(UGUIDrag)),
		_GT(typeof(UIMask)),
        _GT(typeof(UnityEngine.EventSystems.PointerEventData)),
        _GT(typeof(UnityEngine.UI.ScrollRect.ScrollRectEvent)),
        _GT(typeof(UnityEngine.UI.Button.ButtonClickedEvent)),

		//usprite
		_GT(typeof(USprite)),
		_GT(typeof(USpriteUGUI)),

		//utils
		_GT(typeof(AudioManager)),
		_GT(typeof(BesizerUtil)),
		_GT(typeof(CSV)),
		_GT(typeof(DynamicAsset)),
		_GT(typeof(InputUtil)),
		_GT(typeof(MathUtil)),
		_GT(typeof(Matrix2D)),
		_GT(typeof(PlayerPrefsX)),
		_GT(typeof(ResManager)),
		_GT(typeof(ResManager.Asset)),
		_GT(typeof(ResManager.AssetPath)),
		_GT(typeof(ResManager.AssetType)),

		_GT(typeof(SQLiteExtension.SQLite)),

		//custom
		_GT(typeof(LuaFramework.LuaHelper)),
		_GT(typeof(LuaFramework.Util)),
        _GT(typeof(LuaFramework.LuaBehaviour)),
		_GT(typeof(LuaFramework.LuaComponent)),
		_GT(typeof(LuaFramework.LuaCollision3DComponent)).SetBaseType(typeof(LuaFramework.LuaComponent)),
		_GT(typeof(LuaFramework.LuaCollision2DComponent)).SetBaseType(typeof(LuaFramework.LuaComponent)),
		_GT(typeof(LuaFramework.LuaRenderComponent)).SetBaseType(typeof(LuaFramework.LuaComponent)),
		_GT(typeof(LuaFramework.LuaAnimatorComponent)).SetBaseType(typeof(LuaFramework.LuaComponent)),
		_GT(typeof(LuaFramework.LuaUGUIComponent)).SetBaseType(typeof(LuaFramework.LuaComponent)),
		_GT(typeof(LuaFramework.LuaManager)),
		_GT(typeof(LuaFramework.AppConst)),
		_GT(typeof(LuaFramework.AssetBundleManager)),
		_GT(typeof(LuaFramework.AssetsRef))
    };

    public static List<Type> dynamicList = new List<Type>()
	{
		typeof(MeshRenderer),
#if !UNITY_5_4_OR_NEWER
        typeof(ParticleEmitter),
        typeof(ParticleRenderer),
        typeof(ParticleAnimator),
#endif

        typeof(BoxCollider),
        typeof(MeshCollider),
        typeof(SphereCollider),
        typeof(CharacterController),
        typeof(CapsuleCollider),

		typeof(BoxCollider2D),
		typeof(PolygonCollider2D),
		typeof(CircleCollider2D),        
		typeof(EdgeCollider2D),
		typeof(CapsuleCollider2D),

        typeof(Animation),
        typeof(AnimationClip),
        typeof(AnimationState),

        typeof(BlendWeights),
        typeof(RenderTexture),
		typeof(Rigidbody),
		typeof(Rigidbody2D),
    };

    //重载函数，相同参数个数，相同位置out参数匹配出问题时, 需要强制匹配解决
    //使用方法参见例子14
    public static List<Type> outList = new List<Type>()
    {
        
    };
        
    //ngui优化，下面的类没有派生类，可以作为sealed class
    public static List<Type> sealedList = new List<Type>()
    {
        /*typeof(Transform),
        typeof(UIRoot),
        typeof(UICamera),
        typeof(UIViewport),
        typeof(UIPanel),
        typeof(UILabel),
        typeof(UIAnchor),
        typeof(UIAtlas),
        typeof(UIFont),
        typeof(UITexture),
        typeof(UISprite),
        typeof(UIGrid),
        typeof(UITable),
        typeof(UIWrapGrid),
        typeof(UIInput),
        typeof(UIScrollView),
        typeof(UIEventListener),
        typeof(UIScrollBar),
        typeof(UICenterOnChild),
        typeof(UIScrollView),        
        typeof(UIButton),
        typeof(UITextList),
        typeof(UIPlayTween),
        typeof(UIDragScrollView),
        typeof(UISpriteAnimation),
        typeof(UIWrapContent),
        typeof(TweenWidth),
        typeof(TweenAlpha),
        typeof(TweenColor),
        typeof(TweenRotation),
        typeof(TweenPosition),
        typeof(TweenScale),
        typeof(TweenHeight),
        typeof(TypewriterEffect),
        typeof(UIToggle),
        typeof(Localization),*/
    };

    public static BindType _GT(Type t)
    {
        return new BindType(t);
    }

    public static DelegateType _DT(Type t)
    {
        return new DelegateType(t);
    }    


    [MenuItem("Lua/Attach Profiler", false, 151)]
    static void AttachProfiler()
    {
        if (!Application.isPlaying)
        {
            EditorUtility.DisplayDialog("警告", "请在运行时执行此功能", "确定");
            return;
        }

        LuaClient.Instance.AttachProfiler();
    }

    [MenuItem("Lua/Detach Profiler", false, 152)]
    static void DetachProfiler()
    {
        if (!Application.isPlaying)
        {            
            return;
        }

        LuaClient.Instance.DetachProfiler();
    }
}
